package com.cxs.distributedgamedemo.slice;

import com.cxs.distributedgamedemo.ResourceTable;
import com.cxs.distributedgamedemo.util.KvStoreUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.data.distributed.common.Entry;
import ohos.data.distributed.user.SingleKvStore;

import java.util.ArrayList;
import java.util.List;

/*
    游戏手柄页面
 */
public class GamepadAbilitySlice extends AbilitySlice {
    SingleKvStore kvStore = null;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_gamepad);

        kvStore = KvStoreUtils.getKvStore(this);
        initView();
    }

    private void initView() {
        findComponentById(ResourceTable.Id_btn_up).setClickedListener(mListener);
        findComponentById(ResourceTable.Id_btn_down).setClickedListener(mListener);
        findComponentById(ResourceTable.Id_btn_left).setClickedListener(mListener);
        findComponentById(ResourceTable.Id_btn_right).setClickedListener(mListener);
    }


    Component.ClickedListener mListener = c -> {
        System.out.println("=======================");

        switch (c.getId()) {
            case ResourceTable.Id_btn_up: {
                System.out.println("up");
                kvStore.putString("action", "up");
                break;
            }
            case ResourceTable.Id_btn_down: {
                System.out.println("down");
                kvStore.putString("action", "down");

                break;
            }
            case ResourceTable.Id_btn_left: {
                System.out.println("left");
                kvStore.putString("action", "left");

                break;
            }
            case ResourceTable.Id_btn_right: {
                System.out.println("right");
                kvStore.putString("action", "right");

                break;
            }
            case ResourceTable.Id_btn_a: {
                System.out.println("A");
                kvStore.putString("action", "A");

                break;
            }
            case ResourceTable.Id_btn_b: {
                System.out.println("B");
                kvStore.putString("action", "B");

                break;
            }
        }
        System.out.println("=======================");
    };
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
